package ${manager};

import ${mapper}.${table.alias}Mapper;
import ${dto}.${table.alias}PO;
import ${dto}.${table.alias}DTO;
import ${param}.${table.alias}Param;
<#if ifNeedStatistics==true>
import ${counts}.CountsDTO;
</#if>
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import com.fingard.rh.fgmsp.common.exception.MspDbException;

/**
 * @author ${author}
 * @version 1.0 ${date}
 */
@Component
public class ${table.alias}Manager {

    @Autowired
    private ${table.alias}Mapper ${table.propertyName}Mapper;

    public PageInfo<${table.alias}PO> listPage(${table.alias}Param ${table.propertyName}Param){
        PageHelper.startPage(${table.propertyName}Param.getPageNum(), ${table.propertyName}Param.getPageSize(), ${table.propertyName}Param.getOrderBy());
        return new PageInfo<>(${table.propertyName}Mapper.queryBySelective(${table.propertyName}Param));
    }

    public List<${table.alias}PO> queryBySelective(${table.alias}Param ${table.propertyName}) {
        return ${table.propertyName}Mapper.queryBySelective(${table.propertyName});
    }

    public ${table.alias}PO queryByPrimaryKey(<#if ifSpiltByEnt==true>String entNum,</#if> String id) {
        return ${table.propertyName}Mapper.selectByPrimaryKey(<#if ifSpiltByEnt==true>entNum,</#if>id);
    }

    public void insert(${table.alias}PO ${table.propertyName}PO) {
        int i = ${table.propertyName}Mapper.insertSelective(<#if ifSpiltByEnt==true>fingardTransactionsPO.getEnterpriseCode(),</#if> ${table.propertyName}PO);
        if (i != 1) {
            throw new MspDbException();
        }
    }

    public void update(${table.alias}PO ${table.propertyName}PO) {
        int i = ${table.propertyName}Mapper.updateByPrimaryKeySelective(<#if ifSpiltByEnt==true>fingardTransactionsPO.getEnterpriseCode(),</#if> ${table.propertyName}PO);
        if (i != 1) {
            throw new MspDbException();
        }
    }

    public Integer deleteOne(<#if ifSpiltByEnt==true>String entNum,</#if> String id) {
        return ${table.propertyName}Mapper.deleteByPrimaryKey(<#if ifSpiltByEnt==true>entNum,</#if> id);
    }

    public Integer deleteInBatches(<#if ifSpiltByEnt==true>String entNum,</#if> List<String> idList) {
        return ${table.propertyName}Mapper.deleteByPrimaryKeys(<#if ifSpiltByEnt==true>entNum,</#if> idList);
    }

    public PageInfo<${table.alias}DTO> listByParam(${table.alias}Param ${table.propertyName}Param){
        PageHelper.startPage(${table.propertyName}Param.getPageNum(), ${table.propertyName}Param.getPageSize(), ${table.propertyName}Param.getOrderBy());
        return new PageInfo<>(${table.propertyName}Mapper.listByParam(${table.propertyName}Param));
    }

<#if ifNeedStatistics==true>
    public CountsDTO countByParam(${table.alias}Param ${table.propertyName}Param){
        return ${table.propertyName}Mapper.countByParam(${table.propertyName}Param);
    }
</#if>
}